'
' -- hexconvert.bas -- 
' written by CHR.BEST
'
' Little string converter DLL
'
' Copy hexconvert.bas to the Free Basic folder and generate the DLL with: fbc -dll hexconvert.bas
'

option explicit

DECLARE SUB Hex2Bin lib "hexconvert" alias "Hex2Bin" (byval hexstr as ubyte ptr, byval myData AS Integer, byval binstr as ubyte ptr)
DECLARE SUB Bin2Hex lib "hexconvert" alias "Bin2Hex" (byval binstr as ubyte ptr, byval myData AS Integer, byval hexstr as ubyte ptr)

SUB Hex2Bin (byval hexstr as ubyte ptr, byval myData AS Integer, byval binstr as ubyte ptr) EXPORT
 dim i,j as long
 j = 0
 for i = 0 to myData-1 step 2
  binstr[j] = val("&H"+chr$(hexstr[i])+chr$(hexstr[i+1]))
  j = j + 1
 next
end SUB

SUB Bin2Hex (byval binstr as ubyte ptr, byval myData AS Integer, byval hexstr as ubyte ptr) EXPORT
 dim i,j as long
 j = 0
 for i = 0 to myData-1
  hexstr[j] = asc(hex$(binstr[i] shr 4))
  j = j + 1
  hexstr[j] = asc(hex$(binstr[i] and 15))
  j = j + 1
 next
end SUB

